<?php
/**
 * Interview Customizing Screen
 * 
 * In this interface you will be able to customize the interview types
 * and the interview text blocks
 * 
 */

use Fox\Generator;
use Fox\Grid;
$xview = Xview::instance();

// Customizing
$customizing = Hive\Admin\Customizing::instance();
$customizing->trackSummaryPage(array('mod' => 'contacts','act'=>'interviews','sac'=>'admin'));

if(!Fox\Authorization\Manager::check('hive-interviews-customizing')) {
	echo $xview->accessDenied(Msg(Hive::BUNDLE,Hive::ERR_ADMIN_ACCES_DENIED),null,true);
	exit;
}

$screen = new Fox\Html\Screen('sGroups');
$screen->pageTitle(Msg(Hive::BUNDLE,Hive::INTERVIEW_CUSTOMIZING));

// Customize Interview Type
$gTypes = new Grid('gTypes');
$gTypes->bootstrapGrid();
$gTypes->fieldcat(array('label',array('contact_type_code','code'),'standard','active','iedit'))
		->switchToObjectMode()
		->setGenerators(array(
			'label' => Generator::call('label'),
			'iedit' => Generator::useValue('?')
		));
$gTypes->fieldcat()->field('iedit')->renderer()
			->behaviors(Fox\Behaviors::action(
				Fox\Generator::url('contacts','interviews','type_modify',array('inlineid' => Generator::call('getInLineId'))),
			true
		));
$bTypes = new Fox\Html\Button('add','?',Msg(Hive::BUNDLE,Hive::ADD_A_NEW_TYPE));
$bTypes->color(Fox\Html\Button::COLOR_WARNING)
		->behaviors(Fox\Behaviors::action(
			Fox\Generator::url('contacts','interviews','type_modify'),
			true
		));
$gTypes->initialize(Hive\Contact\Interview\Type::loadAll());

$html = $screen->display();
$html .= '<p class="prettyprint">'.$bTypes->display().Msg(Hive::BUNDLE,Hive::YOU_FIND_BELLOW_THE_LIST_OF_INTERVIEWS_CUSTOMIZING_POINTS).'</p>';
$html .= $gTypes->display();
// Customize Interview Status


$typesLabel = array();
foreach(Fox\Dao::finder(Hive\Contact\Interview\Status\Type::className())->where('language = ?',array($xview->language()))->find() as $item) {
	$typesLabel[$item->type] = $item->label;
}
$gStatus = new Grid('gTypes');
$gStatus->bootstrapGrid();
$gStatus->fieldcat(array('label','standard',array('contact_status_type','type'),'active','iedit'))
		->switchToObjectMode()
		->setGenerators(array(
			'label' => Generator::call('label'),
			'iedit' => Generator::useValue('?'),
			'type' => Generator::useFunction(function($data) use($typesLabel){
				return $typesLabel[$data->type];
			})
		));
$gStatus->fieldcat()->field('iedit')->renderer()
			->behaviors(Fox\Behaviors::action(
				Fox\Generator::url('contacts','interviews','status_modify',array('inlineid' => Generator::call('getInLineId'))),
			true
		));
$bStatus = new Fox\Html\Button('add','?',Msg(Hive::BUNDLE,Hive::ADD_A_NEW_STATUS));
$bStatus->color(Fox\Html\Button::COLOR_WARNING)
		->behaviors(Fox\Behaviors::action(
			Fox\Generator::url('contacts','interviews','status_modify'),
			true
		));
$html .= '<br><p class="prettyprint">'.$bStatus->display().Msg(Hive::BUNDLE,Hive::CUSTOMIZE_INTERVIEWS_STATUS).'</p>';
$gStatus->initialize(Hive\Contact\Interview\Status::loadAll());
$html .= $gStatus->display();

return '<div class="source {\'uri\':\'?mod=contacts&act=interviews&sac=admin\'}" >'.$html.'</div>';